package com.xuecheng.auth.controller;

import com.xuecheng.ucenter.mapper.XcUserMapper;
import com.xuecheng.ucenter.model.po.XcUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author itcast
 */
@RestController
@Api(value = "用户相关接口", tags = "用户相关接口")
@RequestMapping("/user")
public class UserController {
    @Resource
    private XcUserMapper userMapper;

    @GetMapping("/getName/{id}")
    @ApiOperation("查询用户姓名")
    public String getName(@PathVariable("id") String id) {
        XcUser xcUser = userMapper.selectById(id);
        if (xcUser == null) {
            return null;
        }

        return xcUser.getName();
    }

    @GetMapping("/listNameByIds")
    @ApiOperation("批量查询用户姓名")
    public Map<String, String> listNameByIds(@RequestParam("ids") List<String> ids) {
        List<XcUser> userList = userMapper.selectBatchIds(ids);
        return userList.stream().collect(Collectors.toMap(XcUser::getId, XcUser::getName));
    }
}
